package com.lcb.jmm.unsafe;

import java.util.concurrent.locks.LockSupport;

/****
 * @Author:刘长柏
 * @Date: 2021-01-05 16:06
 * @Description: 阻塞线程
 *****/
public class ThreadParkerTest {

    public static void main(String[] args) {

        /*Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread - is running----");
                LockSupport.park();//阻塞当前线程
                System.out.println("thread is over-----");
            }
        });

        t.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LockSupport.unpark(t);//唤醒指定的线程*/

        System.out.println("main thread is over");
        //相当于先往池子里放了一张票据
        LockSupport.unpark(Thread.currentThread());//Pthread_mutex

        //拿出票据使用
        LockSupport.park();
        System.out.println("im running step 1");

    }

}
